package com.code.generation.controller;

import com.code.generation.dto.CreateDTO;
import com.code.generation.dto.DataBaseInfo;
import com.code.generation.service.BootService;
import com.code.generation.vo.CreateVO;
import com.code.generation.vo.RespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ProjectName: codegeneration
 * @Package: com.code.generation.controller
 * @Description:
 * @Author: DongJW
 * @CreateDate: 2020/11/29 11:20
 * @Version: 1.0
 */
@CrossOrigin
@Controller
@RequestMapping("/code")
public class CodeGenerationController {

    @Autowired
    private BootService bootService;

    @PostMapping("/generation")
    @ResponseBody
    public RespVO codeGeneration(@RequestBody CreateVO createVO)throws Exception{

        BeanCopier beanCopier = BeanCopier.create(CreateVO.class,CreateDTO.class,false);
        CreateDTO createDTO = new CreateDTO();
        beanCopier.copy(createVO, createDTO, null);
        DataBaseInfo dataBaseInfo = new DataBaseInfo();
        dataBaseInfo.setDataBaseType(createVO.getDataBaseType());
        dataBaseInfo.setDb(createVO.getDb());
        dataBaseInfo.setIp(createVO.getIp());
        dataBaseInfo.setPort(createVO.getPort());
        dataBaseInfo.setUsername(createVO.getUsername());
        dataBaseInfo.setPassword(createVO.getPassword());
        createDTO.setDataBaseInfo(dataBaseInfo);

        bootService.create(createDTO);
        return new RespVO();
    }


}

